package com.opener.common.code.assistant.model;

public class Prop {
    private String dbField;
    private String javaProp;
    private String dbType;
    private String javaType;
    private String comment;

    public String getDbField() {
        return dbField;
    }

    public void setDbField(String dbField) {
        this.dbField = dbField;
    }
    public String getJavaFieldName(String s){
        if (s == null){
            return null;
        }
        String[] a = s.split("_");
        StringBuffer javaProp = new StringBuffer();
        for (int i = 0; i< a.length; i++){
            String segment = a[i];
            if (i>0){
                segment = segment.replaceAll("^\\w",segment.substring(0,1).toUpperCase());
            }
            javaProp.append(segment);
        }
        return javaProp.toString();
    }
    public String getJavaProp() {
        if (javaProp == null){
            javaProp = getJavaFieldName(dbField);
        }
        return javaProp;
    }

    public void setJavaProp(String javaProp) {
        this.javaProp = javaProp;
    }

    public String getDbType() {
        return dbType;
    }

    public void setDbType(String dbType) {
        this.dbType = dbType;
    }

    public String getJavaType() {
        if (javaType == null){


            if ( "tinyint".equalsIgnoreCase(dbType) ){
                javaType = "boolean";
            }else if ( dbType!=null && dbType.indexOf("bigint")>=0 ){
                javaType = "Long";
            }else if ( dbType!=null && dbType.indexOf("int")>=0 ){
                javaType = "Integer";
            }else if (dbType.indexOf("decimal")>=0){
                javaType = "BigDecimal";
            }else if ("varchar".equalsIgnoreCase(dbType) || "char".equalsIgnoreCase(dbType) || "enum".equalsIgnoreCase(dbType)){
                javaType = "String";
            }else if ("datetime".equalsIgnoreCase(dbType) || "date".equalsIgnoreCase(dbType) || "timestamp".equalsIgnoreCase(dbType)){
                javaType = "Date";
            }else if ("float".equalsIgnoreCase(dbType)){
                javaType = "Float";
            }else if ("double".equalsIgnoreCase(dbType)){
                javaType = "Double";
            }else if ("set".equalsIgnoreCase(dbType)){
                javaType = "List";
            }
        }
        return javaType;
    }

    public void setJavaType(String javaType) {
        this.javaType = javaType;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }
}
